package com.bw.module_publish

import android.os.Bundle
import android.view.SurfaceHolder
import android.view.SurfaceView
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.bw.lib_avcore.Config
import com.bw.lib_avcore.MediaPublisher
import com.bw.lib_avcore.VideoHelper

class PublushActivity : AppCompatActivity(),SurfaceHolder.Callback {
    private lateinit var surfaceView: SurfaceView
    private lateinit var videoHelper: VideoHelper
    private lateinit var config: Config


    private lateinit var publisher: MediaPublisher
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_publush)
        surfaceView = findViewById(R.id.surface_view)
        surfaceView.holder.addCallback(this)
        //参数配置
        config = Config.Builder()
            .setFps(60)
            .build()

        publisher = MediaPublisher.getInstance(config)
        publisher.init()

    }

    override fun surfaceCreated(holder: SurfaceHolder) {
        publisher.initVideoGather(holder) //初始化视频采集

    }

    override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {

    }

    override fun surfaceDestroyed(holder: SurfaceHolder) {

    }

    fun startPublish(view: View) {
        publisher.initEncoders()
        publisher.startEncoder()
    }
}